//
//  ViewController.m
//  11-23tableView
//
//  Created by blue on 15-11-23.
//  Copyright (c) 2015年 hyd. All rights reserved.
//

#import "ViewController.h"
#import "inputViewController.h"
@interface ViewController ()<InputFinshDelegate>{

    NSArray * data;
    NSArray * tels;
    NSIndexPath * curIndexPath;
}
@end

@implementation ViewController



- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    self.title = @"我的通讯录";
    data = @[
             @"曾勇",
             @"余炟",
             @"苏苏",
             @"汪晓",
             @"黄艳端"
             ];
    
    tels = @[
             @"13245678901",
             @"15248795622",
             @"13657895623",
             @"13585421684",
             @"18225341095"
             ];
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return data.count;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.textLabel.text = data[indexPath.row];
    cell.detailTextLabel.text = tels[indexPath.row];
       cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    inputViewController * con = [[inputViewController alloc]initWithStyle:UITableViewStyleGrouped];
//    con.curIndexPath=tels[indexPath.row];
    
    con.tel = tels[indexPath.row];
    con.delegate = self;
    [self.navigationController pushViewController:con animated:YES];
    


}

- (void)inputFinished:(NSString *)text
{
    NSMutableArray * arr = tels.mutableCopy;
    [arr replaceObjectAtIndex:curIndexPath.row withObject:text];
    tels = arr;
    [self.tableView reloadData];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
